package config

import (
	"io/ioutil"

	"gopkg.in/yaml.v2"
)

var Cfg *config

func file2Model() {
	list := []string{
		"config/mysql.yml",
		"config/config.yml",
	}

	for _, name := range list {
		bytes, err := ioutil.ReadFile(name)
		Err("读取配置文件出错 ===> ", err)
		_ = yaml.Unmarshal(bytes, &Cfg)
	}
}

// 定义配置文件
type config struct {
	LogName string   `yaml:"log_name"`
	Server  struct { // 程序基础配置
		Port    string `yaml:"port"`
		IsHttps bool   `yaml:"https"`
	} `yaml:"server"`
	Redis struct { // redis数据库连接
		Ip   string `yaml:"ip"`
		Port string `yaml:"port"`
		Pwd  string `yaml:"pwd"`
		Db   int    `yaml:"db"`
	} `yaml:"redis"`
	Mysql []mysqlConn `yaml:"mysql"`
}

// mysql连接定义
type mysqlConn struct {
	Ip       string `yaml:"ip"`
	Port     string `yaml:"port"`
	User     string `yaml:"user"`
	Pwd      string `yaml:"pwd"`
	Db       string `yaml:"db"`
	OpenConn int    `yaml:"open_conn"`
	IdleConn int    `yaml:"idle_conn"`
}
